<template>
  <div id="login">
    <div id="center">
      <div class="c-box">
        <h2>梦学谷会员管理系统</h2>
      </div>
      <section>
        <el-form
          label-width="100px"
          class="demo-ruleForm"
          :rules="rules"
          :model="ruleForm"
          ref="ruleForm"
        >
          <el-form-item prop="username">
            <el-input
              style="padding:'0 40px'"
              placeholder="请输入你的用户名"
              v-model="ruleForm.username"
              prefix-icon="el-icon-user-solid"
            ></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              placeholder="请输入你的密码"
              v-model="ruleForm.password"
              type="password"
              prefix-icon="el-icon-s-order"
            ></el-input>
          </el-form-item>
          <el-form-item class="right">
            <el-button type="primary" @click="login">登录</el-button>
          </el-form-item>
        </el-form>
      </section>
    </div>
  </div>
</template> 
<script>
export default {
  data() {
    return {
      ruleForm: {
        username: "admin",
        password: "123456"
      },
      rules: {
        username: [
          { required: true, message: "请输入正确的用户名", trigger: "blur" },
          { min: 4, max: 8, message: "长度在 4 到 8 个字符", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入正确的密码", trigger: "blur" },
          { min: 4, max: 8, message: "长度在 4 到 8 个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    login() {
      this.$refs.ruleForm.validate(async valid => {
        //   console.log(valid) true
        if (valid) {
              this.$message.success('登录成功')
              this.$router.push('/home')
              sessionStorage.setItem('loginUsername',JSON.stringify(this.ruleForm))
        }
      });
    },
    resetForm(ruleForm) {
      this.$refs.ruleForm.resetFields();
      console.log(this.ruleForm);
    }
  }
};
</script>
<style lang="scss" scoped>
#login {
  width: 100%;
  height: 100%;
  background: url('../../assets/aa18972bd40735fa015c82359c510fb30e24088a.jpg')no-repeat center center;
  background-size: 100% 100%;
  #center {
    position: absolute;
    right: 0;
    top: 60%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px #ddd;
    width: 450px;
    height: 304px;
    border-radius: 3px;
  background-color: hsla(0,0%,100%,.8);
    section {
      padding: 20px;
      // padding-top: 100px;
    }
    .c-box{
          margin-top: 50px;
          padding-left: 60px;
    }
  }
}
.right {
  float: right;
}
/deep/.el-form-item__content {
  margin-left: 0 !important;
  padding: 0 40px !important;
}
/deep/.el-form-item__error {
  padding: 4px 40px !important;
}
</style>

